package com.jiazhong.boot.jwt.controller;

import com.jiazhong.boot.commons.bean.plus.User;
import com.jiazhong.boot.commons.config.JwtConfig;
import com.jiazhong.boot.commons.util.JsonResult;
import com.jiazhong.boot.commons.util.ResultTool;
import com.jiazhong.boot.jwt.service.UserService;
import io.jsonwebtoken.Claims;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;

@CrossOrigin
// 专门负责登陆、注销等权限认证相关的控制器
@RestController
@RequestMapping("/auth")
public class AuthController {
    @Resource
    private UserService service;
    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @PostMapping("/login")
    public JsonResult login(User user) {
        return service.login(user);
    }

    @GetMapping("/is_login")
    public JsonResult isLogin(HttpServletRequest request) {
        return service.isLogin(request.getHeader("token"));
    }

    @DeleteMapping("/logout")
    public JsonResult logout(HttpServletRequest request) {
        return service.logout(request.getHeader("token"));
    }
}
